{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## This notebook handling Preprocessing and Feature Manipulations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import required libs\n",
    "\n",
    "from preprocessing import Preprocessing\n",
    "from segmentaion import Segmentation\n",
    "from matplotlib import pyplot as plt\n",
    "from skimage import io\n",
    "%matplotlib inline\n",
    "import numpy as np\n",
    "from skimage.feature import greycomatrix, greycoprops\n",
    "from skimage import data\n",
    "from skimage.color import rgb2gray"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### # Run  preprocessing and Segmentation on images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# you can make a loop to handling all images at once \n",
    "preprocessing = Preprocessing()\n",
    "preprocessing.preproces('/home/mu7ammad/workspace/Pythonwork/nmpy/GP/im_Pr/SG/G_P/Cl/ab6.jpg')\n",
    "preprocessing.binarization()\n",
    "preprocessing.removingSkul()\n",
    "preprocessing.enhanceImage()\n",
    "preprocessing.segmentation()\n",
    "image = preprocessing.getInfectedRegion()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# read and show image \n",
    "im = io.imread('tmp/tumourImage.jpg')\n",
    "plt.imshow(im, 'gray')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Extract GLCM Texture  Features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# GLCM Texture Features\n",
    "ds = []\n",
    "cr = []\n",
    "cn = []\n",
    "am = []\n",
    "en = []\n",
    "ho = []\n",
    "\n",
    "glcm = greycomatrix(im, [5], [0], symmetric=True, normed=True)\n",
    "ds.append(greycoprops(glcm, 'dissimilarity')[0,0])\n",
    "cr.append(greycoprops(glcm, 'correlation')[0,0])\n",
    "cn.append(greycoprops(glcm, 'contrast')[0,0])\n",
    "am.append(greycoprops(glcm, 'ASM')[0,0])\n",
    "en.append(greycoprops(glcm, 'energy')[0,0])\n",
    "ho.append(greycoprops(glcm, 'homogeneity')[0,0])\n",
    "    \n",
    "    \n",
    "print('dissimilarity',ds)\n",
    "print('correlation',cr)\n",
    "print('contrast',cn)\n",
    "print('ASM',am)\n",
    "print('energy',en)\n",
    "print('homogeneity',ho)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## This is an example of features we extract"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ab5\n",
    "('dissimilarity', [21.110660774520827])\n",
    "('correlation', [0.83426829249573753])\n",
    "('contrast', [5321.9157231388745])\n",
    "('ASM', [0.34060852538803205])\n",
    "('energy', [0.58361676242893512])\n",
    "('homogeneity', [0.85598676802301221])\n",
    "ab4\n",
    "('dissimilarity', [17.544127747252752])\n",
    "('correlation', [0.81400737463685935])\n",
    "('contrast', [4425.5988201812561])\n",
    "('ASM', [0.50246861831414891])\n",
    "('energy', [0.70885020865775927])\n",
    "('homogeneity', [0.88572655336637995])\n",
    "ab6\n",
    "('dissimilarity', [13.017361750336331])\n",
    "('correlation', [0.87518943465934507])\n",
    "('contrast', [3287.6100757629397])\n",
    "('ASM', [0.50099757475878692])\n",
    "('energy', [0.70781182157321088])\n",
    "('homogeneity', [0.91962504352100038])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
